package leetcode;

/**
 * @author Liangyaoyun
 */
public class leetCode91 {
    public int numDecodings(String s) {
        int len=s.length();
        int[] dp=new int[len+1];
        if (s.length()==0){
            return 0;
        }
        if (s.charAt(0)=='0'){
            return 0;
        }
        dp[0]=1;
        for (int i = 0; i <len ; i++) {
            //11106
            dp[i+1]=s.charAt(i)=='0'?0:dp[i];
            if (i>0&&(s.charAt(i-1)=='1'||(s.charAt(i-1)=='2'&&s.charAt(i)<='6'))){
                dp[i+1]+=dp[i-1];
            }
        }
        return dp[len];
    }

    public static void main(String[] args) {
        String s="11106";
        leetCode91 leetCode91=new leetCode91();
        System.out.println(leetCode91.numDecodings(s));
    }
}
